package 蓝桥杯.第十四届蓝桥杯大赛软件赛省赛Java大学B组;

import java.util.*;

/**
 * @Title: 买二赠一
 * @Author 贾金博
 * @Package 蓝桥杯.第十四届蓝桥杯大赛软件赛省赛Java大学B组
 * @Date 2024/4/11 18:22
 * @description:
 */
public class 买二赠一 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n + 10 ];

        for(int i = 1; i <= n; ++ i ) {
            a[i] = sc.nextInt();
        }

        Arrays.sort(a, 1, n + 1);

        long ret = 0;
        Queue<Integer>q = new LinkedList<>();

        for(int i = n; i >= 1; -- i ) {
            q.add(a[i]);
        }

        if(q.size() == 1) {
            System.out.println(a[1]);
            return;
        }

        List arrayList = new ArrayList();

        for(int i = 1; i <= n; ++ i ) {
            arrayList.add(a[i]);
        }

        while(!q.isEmpty()) {
            if(q.size() == 1) {
                break;
            }
            int t1 = q.poll();
            int t2 = q.poll();
            ret += t1 + t2;
            int find = Math.min(t1, t2) / 2;
            //删除掉
            arrayList.remove(Integer.valueOf(t1));
            arrayList.remove(Integer.valueOf(t2));
            int l = 0, r = arrayList.size();
            while(l + 1 < r) {
                int mid = (l + r) >> 1;
                if((int)arrayList.get(mid) <= find)l = mid;
                else r = mid;
            }
            if(q.size() != 0 ) {
                q.remove((Integer) arrayList.get(l));
                arrayList.remove(l); // 删除的是位置index
            }
        }
        while(q.size() != 0 ) {
            ret += q.poll();
        }
        System.out.println(ret);
    }
}
